package com.lucky.common.config.security;

import com.lucky.common.pojo.po.UserPO;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;


@Getter
@Setter
public class AppUserDetail implements UserDetails {

    public UserPO userPO;
    public UserDetails user;
    public List<String> roles;
    public List<String> perms;

    public AppUserDetail(UserPO user) {this.userPO = user;}

    public AppUserDetail(UserDetails user, List<String> roles, List<String> perms) {
        this.user = user;
        this.roles = roles;
        this.perms = perms;
    }

    public Long getId(){
        return userPO.getId();
    }

    public String getUsername(){
        return user.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public String getPassword(){
        return user.getPassword();
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return user.getAuthorities();
    }
}
